package org.oyrm.kobo.formBuilder.ui;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

import org.oyrm.kobo.formBuilder.actions.StartPostProcessorAction;
import org.oyrm.kobo.formBuilder.controller.IFormBuilderListener;
import org.oyrm.kobo.formBuilder.settings.Settings;

/**
 * The main tool bar for the Form Builder
 * @author etherton
 *
 */
public class MainToolBar extends JToolBar {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3898258959406786523L;

	/**
	 * Open button
	 */
	private JButton openBtn = null;
	
	/**
	 * Save button
	 */
	private JButton saveBtn = null;
	
	/**
	 * Save as button
	 */
	private JButton saveAsBtn = null;
	
	/**
	 * Load From Text button
	 */
	private JButton loadFromTextBtn = null;
	
	/**
	 * View Form Text button
	 */
	private JButton viewFormTextBtn = null;
	
	/**
	 * Cut button
	 */
	private JButton cutBtn = null;
	
	/**
	 * Copy button
	 */
	private JButton copyBtn = null;
	
	/**
	 * Paste Button
	 */
	private JButton pasteBtn = null;
	
	/**
	 * Edit Locales Button
	 */
	private JButton editLocalesBtn = null;	
		
	/**
	 * Post Processor button
	 */
	private JButton postProcessorBtn = null;
	
	/**
	 * The controller for controlling things	
	 */
	private IFormBuilderListener controller = null;
		
	
	public MainToolBar(IFormBuilderListener controller)
	{
		super();
		this.controller = controller;
		createComponents();
		placeComponents();
	}

	/**
	 * Creates all the components
	 */
	private void createComponents() {
		
		setAlignmentX(0);
		ImageIcon tempIcon;
		
		tempIcon = new ImageIcon(getClass().getResource("/resources/open_file.png"));
		openBtn = new JButton(tempIcon);
		openBtn.setToolTipText(Settings.getI18n().getString("openFileText"));
		
		tempIcon = new ImageIcon(getClass().getResource("/resources/save_file.png"));
		saveBtn = new JButton(tempIcon);
		saveBtn.setToolTipText(Settings.getI18n().getString("SaveFileText"));
		
		tempIcon = new ImageIcon(getClass().getResource("/resources/save_file_as.png"));
		saveAsBtn = new JButton(tempIcon);
		saveAsBtn.setToolTipText(Settings.getI18n().getString("SaveFileAsText"));
		
		tempIcon = new ImageIcon(getClass().getResource("/resources/load.png"));
		loadFromTextBtn = new JButton(tempIcon);
		loadFromTextBtn.setToolTipText(Settings.getI18n().getString("loadFromText"));
		
		tempIcon = new ImageIcon(getClass().getResource("/resources/showxml.png"));
		viewFormTextBtn = new JButton(tempIcon);
		viewFormTextBtn.setToolTipText(Settings.getI18n().getString("viewFormText"));
					
		tempIcon = new ImageIcon(getClass().getResource("/resources/cut.png"));
		cutBtn = new JButton(tempIcon);
		cutBtn.setToolTipText(Settings.getI18n().getString("cutText"));
		
		tempIcon = new ImageIcon(getClass().getResource("/resources/copy.png"));
		copyBtn = new JButton(tempIcon);
		copyBtn.setToolTipText(Settings.getI18n().getString("copyText"));
		
		tempIcon = new ImageIcon(getClass().getResource("/resources/paste.png"));
		pasteBtn = new JButton(tempIcon);
		pasteBtn.setToolTipText(Settings.getI18n().getString("pasteText"));
		
		tempIcon = new ImageIcon(getClass().getResource("/resources/localization.png"));
		editLocalesBtn = new JButton(tempIcon);
		editLocalesBtn.setToolTipText(Settings.getI18n().getString("editLocalesText"));

		tempIcon = new ImageIcon(getClass().getResource("/resources/postprocess.png"));
		postProcessorBtn = new JButton(new StartPostProcessorAction(controller));
		postProcessorBtn.setIcon(tempIcon);
		postProcessorBtn.setToolTipText(Settings.getI18n().getString("postProcessorMenuItemText"));
		

		
	}

	
	/**
	 * Places all the components in the right places
	 */
	private void placeComponents() {
		this.add(openBtn);
		this.add(saveBtn);
		this.add(saveAsBtn);
		this.add(loadFromTextBtn);
		this.add(viewFormTextBtn);
		

		Separator separator = new Separator();
		this.add(separator);

		this.add(cutBtn);
		this.add(copyBtn);
		this.add(pasteBtn);
		
		separator = new Separator();
		this.add(separator);
		
		this.add(editLocalesBtn);
		
		separator = new Separator();
		this.add(separator);
		
		this.add(postProcessorBtn);
		
		
	}

	
	
}
